//
//  CateDropBtn.m
//  小团购
//
//  Created by 樊荣海 on 15/1/23.
//  Copyright (c) 2015年 樊荣海. All rights reserved.
//

#import "CateDropBtn.h"
#define imageScale 0.4

@implementation CateDropBtn 

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self == [super initWithFrame:frame]) {
        
        self.imageView.contentMode = UIViewContentModeCenter;

        [self.titleLabel setTextAlignment:NSTextAlignmentCenter];
//        [self setTitleColor:[UIColor whiteColor] forState:UIControlStateDisabled];
        [self setTitleColor:globalTintColor forState:UIControlStateNormal];
        [self.titleLabel setFont:[UIFont systemFontOfSize:12]];
//
//        [self addTarget:self action:@selector(locationClick) forControlEvents:UIControlEventTouchDown];
   
        // 1.右边的分割线
//        UIImage *img = [UIImage imageNamed:@"separator_filter_item.png"];
//        UIImageView *divider = [[UIImageView alloc] initWithImage:img];
//        divider.bounds = CGRectMake(0, 0, 0.5, DropScrollViewH * 0.7);
//        divider.center = CGPointMake(DropScrollViewW, DropScrollViewH * 0.5);
//        [self addSubview:divider];
        
        
        //2.设置 没选中/选中时的bgColor
//        [self setBackgroundImage:[UIImage resizedImage:@"selected_bg"] forState:UIControlStateSelected];
        
        
    }
    
    return self;
    
}

- (NSArray *)titles {

    return _model.subcategories;
}



- (void)setModel:(CateModel *)model {

    _model = model;
    
    [self setImage:[UIImage imageNamed:model.icon] forState:UIControlStateNormal];
    [self setTitle:model.name forState:UIControlStateNormal];
}

- (void)setHighlighted:(BOOL)highlighted {}

//宽度写死
- (void)setFrame:(CGRect)frame {
    
    frame.size = CGSizeMake(DropScrollViewW, DropScrollViewH);
    [super setFrame:frame];
}

- (void)setBounds:(CGRect)bounds {
    
    bounds.size = CGSizeMake(DropScrollViewW, DropScrollViewH);
    [super setBounds:bounds];
}

- (CGRect)imageRectForContentRect:(CGRect)contentRect {
    
    return CGRectMake(0, 10, contentRect.size.width, contentRect.size.height*imageScale);
}

- (CGRect)titleRectForContentRect:(CGRect)contentRect {
    
    return CGRectMake(0, contentRect.size.height*imageScale, contentRect.size.width, contentRect.size.height*(1-imageScale));
}

@end
